const fs = require('fs');
const path = require('path');

// 获取books目录路径
const booksDir = path.join(__dirname, 'books');

// 检查books目录是否存在
if (!fs.existsSync(booksDir)) {
  console.log('Books directory does not exist');
  process.exit(1);
}

// 读取books目录下的所有组目录
const groupDirs = fs.readdirSync(booksDir).filter(dir => 
  fs.statSync(path.join(booksDir, dir)).isDirectory()
);

console.log(`Found ${groupDirs.length} groups`);

// 查找所有不包含名为"11"的子目录的书籍目录
const booksMissingPage11 = [];

for (const groupDir of groupDirs) {
  const groupPath = path.join(booksDir, groupDir);
  // 获取组内的所有书籍目录
  const bookDirs = fs.readdirSync(groupPath).filter(dir => 
    fs.statSync(path.join(groupPath, dir)).isDirectory()
  );
  
  // 检查每本书是否包含"11"子目录
  for (const bookDir of bookDirs) {
    const bookPath = path.join(groupPath, bookDir);
    const pageDirs = fs.readdirSync(bookPath).filter(dir => 
      fs.statSync(path.join(bookPath, dir)).isDirectory()
    );
    
    // 检查是否存在名为"11"的子目录
    if (!pageDirs.includes('11')) {
      booksMissingPage11.push({
        group: groupDir,
        book: bookDir,
        path: path.join(groupDir, bookDir)
      });
    }
  }
}

// 输出结果
console.log(`\nFound ${booksMissingPage11.length} books missing page "11":`);
if (booksMissingPage11.length > 0) {
  booksMissingPage11.forEach(item => console.log(`- ${item.path}`));
} else {
  console.log('All books have page "11"');
}